package com.cjh.utils;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
 * 生产者配置类-routing-direct
 */
@Configuration
public class RoutingDirectConfig {
    /**
     * 声明交换机
     */
    @Bean
    public DirectExchange directExchange() {
        DirectExchange directExchange = new DirectExchange("directs");
        return directExchange;
    }

    /**
     * 声明队列 1 绑定 info 和 warm
     */
    @Bean
    public Queue queue1() {
        return new Queue("queue1");
    }

    /**
     * 声明队列 2
     */
    @Bean
    public Queue queue2() {
        return new Queue("queue2");
    }

    /**
     * 把队列 1 绑定到交换机里面指定 info 的路由 key
     */
    @Bean
    public Binding binding11() {
        Binding binding = BindingBuilder.bind(queue1())
                .to(directExchange()).with("info");
        return binding;
    }

    /**
     * 把队列 1 绑定到交换机里面指定 warm 的路由 key
     */
    @Bean
    public Binding binding12() {
        Binding binding = BindingBuilder.bind(queue1())
                .to(directExchange()).with("warm");
        return binding;
    }

    /**
     * 把队列 2 绑定到交换机里面指定 debug 的路由 key
     */
    @Bean
    public Binding binding21() {
        Binding binding = BindingBuilder.bind(queue2())
                .to(directExchange()).with("debug");
        return binding;
    }

    /**
     * 把队列 2 绑定到交换机里面指定 error 的路由 key
     */
    @Bean
    public Binding binding22() {
        Binding binding = BindingBuilder.bind(queue2())
                .to(directExchange()).with("error");
        return binding;
    }
}